import { Controller, Post, Body } from '@nestjs/common';
import { PermissionService } from './permission.service';
import { CreatePermissionDto, FindPermissionDto, UpdatePermissionDto, RemovePermissionDto, CreateBatchPermissionDto, RemoveBatchPermissionDto } from './dto/permission.dto';
import { Authority } from '@/common/decorators/authority.decorator';
import { useResult } from '@/common/hooks/useResult';

@Controller('permission')
export class PermissionController {
  constructor(private readonly permissionService: PermissionService) {}

  @Post('create')
  @Authority('permission:create')
  async create(@Body() body: CreatePermissionDto) {
    const res = await this.permissionService.create(body);
    return useResult(res);
  }

  @Post('findAll')
  @Authority('permission:find')
  async findAll(@Body() body: FindPermissionDto) {
    const res = await this.permissionService.findAll(body);
    return useResult(res);
  }

  @Post('findOne')
  @Authority('permission:find')
  async findOne(@Body() body: FindPermissionDto) {
    const res = await this.permissionService.findOne(body);
    return useResult(res);
  }

  @Post('update')
  @Authority('permission:update')
  async update(@Body() body: UpdatePermissionDto) {
    const res = await this.permissionService.update(body);
    return useResult(res);
  }

  @Post('remove')
  @Authority('permission:remove')
  async remove(@Body() body: RemovePermissionDto) {
    const res = await this.permissionService.remove(body);
    return useResult(res);
  }

  @Post('removeBatch')
  @Authority('permission:remove')
  async removeBatch(@Body() body: RemoveBatchPermissionDto) {
    const res = await this.permissionService.removeBatch(body);
    return useResult(res);
  }

  @Post('createBatch')
  @Authority('permission:create')
  async createBatch(@Body() body: CreateBatchPermissionDto) {
    const res = await this.permissionService.createBatch(body);
    return useResult(res);
  }
}
